package com.getword.service.impl;


import com.getword.domain.Article;
import com.getword.domain.Video;
import com.getword.mongodao.ArticleRepository;
import com.getword.mongodao.VideoRepository;
import com.getword.service.SearchService;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private ArticleRepository articleRepository;
    @Autowired
    private VideoRepository videoRepository;
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public Result searchArticle(Pageable page, String key) {
        if(key==null){
            key = "";
        }
//        Page<Article> articles = articleRepository.findByTitleLikeOrKeywordsContaining(key, key, page);
//        return Result.success(articles);
        return null;
    }


    @Override
    public Result searchVideo(Pageable page, String key) {
        if(key==null){
            key = "";
        }
        Page<Video> result = videoRepository.findByTitleLikeOrKeywordsContaining(key, key, page);
        return Result.success(result);
    }
}
